#include <stdio.h>
#include <regex.h>

int main(void) 
{
    const char *pattern = "abc";
    const char *target = "xxabcdefg";

    regex_t reg;
    int ret = regcomp(&reg, pattern, REG_EXTENDED);
    if (ret != 0) {
        printf("regcomp failed, ret = %d\n", ret);
        return -1;
    }

    const size_t nmatch = 2;
    regmatch_t pmatch[2];
    ret = regexec(&reg, target, nmatch, pmatch, 0);
    if (ret != 0) {
        printf("regexec failed, ret = %d\n", ret);
        return -1;
    }

    for (int i = 0; i < 2; i++) {
        printf("pmatch[%d].rm_so = %lld, rm_eo = %lld\n", i, pmatch[i].rm_so, pmatch[i].rm_eo);
    }

    regfree(&reg);
	return 0;
}
